public class Demo13 {
    public static void main(String[] args) throws InterruptedException{
        Thread t=new Thread(()->{
            //先获取到线程的引用
            Thread currentThread=Thread.currentThread();
            while (!currentThread.isInterrupted()){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();

        Thread.sleep(3000);
        //在主线程中,控制t线程被终止,设置上述标志位
        t.interrupt();
    }
}
